using System.Data.Entity.Migrations;
using Abp.MultiTenancy;
using Abp.Zero.EntityFramework;
using SingleUserMall.Migrations.SeedData;
using EntityFramework.DynamicFilters;

namespace SingleUserMall.Migrations
{
    public sealed class Configuration : DbMigrationsConfiguration<SingleUserMall.EntityFramework.SingleUserMallDbContext>, IMultiTenantSeed
    {
        public AbpTenantBase Tenant { get; set; }

        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
            AutomaticMigrationDataLossAllowed = true;
            ContextKey = "WXSC";
        }

        protected override void Seed(SingleUserMall.EntityFramework.SingleUserMallDbContext context)
        {
            context.DisableAllFilters();

            if (Tenant == null)
            {
                //Host seed
                new InitialHostDbBuilder(context).Create();

                //Default tenant seed (in host database).
                new DefaultTenantCreator(context).Create();
                new TenantRoleAndUserBuilder(context, 1).Create();
                new DefaultStoresCreator(context).Create();
                new DefaultCommissionCreator(context).Create();
                new DefaultSmsCreator(context).Create();
                new DefaultLogsticsCreator(context).Create();
            }
            else
            {
                //You can add seed for tenant databases and use Tenant property...
            }
        }
    }
}
